//控制层
app.controller('houseController', function ($scope, $controller, houseService) {

    $controller('baseController', {$scope: $scope});//继承baseController


    /**
     *  linyang
     *  查询所有
     */
    $scope.findAll = function () {
        houseService.findAll().success(
            function (response) {
                if (response.flag) {
                    $scope.list = response.data
                } else {
                    alert(response.msg);
                }
            }
        )
    }

    /**
     * 无条件分页查询
     * linyang
     * @param page
     * @param size
     */
    $scope.findPage = function (page, size) {
        houseService.findPage(page, size).success(
            function (response) {
                $scope.list = response.rows
                $scope.paginationConf.totalItems = response.total
            })
    }

    //定义一个查询实体类
    $scope.searchEntity = {};

    $scope.search = function (page, size)
    {
        houseService.search(page,size, $scope.searchEntity ).success(
            function (response) {
                $scope.list = response.rows
                $scope.paginationConf.totalItems = response.total
            }
        )
    }

    $scope.entity = {};

    /**
     * linyang
     * 查询城市和楼盘公司下啦列表
     */
    $scope.selectHouseList = function () {
        //查询城市列表
        houseService.selectHouseCityList().success(
            function (response) {
                $scope.cityList = response.data;
            }
        )

        houseService.selectHouseBuiltList().success(
            function (response) {
                $scope.companyList = response.data;
            }
        )

        houseService.selectHouseCommunitynameList().success(
            function (response) {
                $scope.communitynameList = response.data;
            }
        )

        houseService.selectHouseAreaList().success(
            function (response) {
                $scope.AreaList = response.data;
            }
        )

        houseService.selectHousebedsList().success(
            function (response) {
                $scope.bedsList = response.data;
            }
        )
    }

    /**
     * 删除/批量删除
     */
    $scope.delete = function  () {
        if($scope.selectedIds.length > 0)
        {
          if(true ==window.confirm("确定要删除吗?"))
          {
              houseService.delete($scope.selectedIds).success(
                  function (response) {
                      if(response.flag)
                      {
                          alert(response.msg)
                          location.href = "house.html";
                      }
                      else
                      {
                          alert("删除失败")
                      }
                  }
              )
          }

        }

    }
})